home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / MyNewCard-c / MyNewCard.c next >
Encoding:
Text File  |  1994-12-04  |  7.4 KB  |  344 lines  |  [TEXT/MMCC]

  1. /*
  2. From: kenlong@netcom.com (Ken Long)
  3. Subject: MyNewCard.c
  4.  
  5. Same as the one in my last post, here, except Matt Mora modified it to 
  6. display the color icon.  I had no experience with any "IconSuite" 
  7. headers, nor did I get any of them with any of the programming 
  8. environments I have (bummer).  So I got the proto from a Think Reference 
  9. example code copy and pasted it into Icon.h, which worked.  Evedently, 
  10. those "suite" protos are in some new Icons.h, because Matt had it 
  11. included.  I don't recall the inclusion being there before.
  12.  
  13. Anyway, I changed the zoomRects to a solid line (from a gray pat), and 
  14. centered the origin of the zoom at the top.
  15.  
  16. By the way, ZoomRect.c and .h are part of the Mac Prog Secrets source 
  17. (not where this came from, though).
  18.  
  19. You'll need a resource with an 'icl8' in a project with MacTraps and ANSI 
  20. to run this without substituting the .c file in "MyCard" project.
  21.  
  22. Enjoy!
  23.  
  24. -Ken-
  25. */
  26.  
  27. //• MyCard.c
  28.  
  29. //#include <icons.h>
  30.  
  31. #define        ONE         65536L
  32. #define        ZOOMSTEPS    16
  33.  
  34. WindowPtr        aboutW;
  35. Rect            aRect, cRect;
  36. char            aStr[255];
  37. EventRecord        aboutEvt;
  38. Boolean            aboutDone;
  39. Fixed    fract;
  40. SysEnvRec gMac;
  41.  
  42. //• Prototypes.
  43.  
  44. pascal OSErr PlotIconID(Rect * theRect, short alignment,
  45.         short transform, short theResID) 
  46.         = {0x303C, 0x0500, 0xABC9};
  47.  
  48. void    drawabout (void);
  49. void    NewAbout (void);
  50. int        Blend (int i1, int i2);
  51. void        zoomrect (Rect *smallrect, Rect *bigrect, Boolean zoomup);
  52. void        ltog (Rect *r);
  53. void        zoomport (WindowPtr wind, Boolean up);
  54. void        centerwindow (WindowPtr wind, Rect *r);
  55. void        centerrect (Rect *r1, Rect *r2);
  56. void    InitMacintosh (void);
  57. void        main (void);
  58.  
  59. void drawabout (void) 
  60. {
  61.     //• Draw the contents of the "About..." window.
  62.     
  63.     Handle ourIcon;
  64.     Rect iconRect;
  65.     
  66.     
  67.     TextFont (0);
  68.     TextSize (18);
  69.  
  70.     ForeColor (blueColor);
  71.  
  72.     strcpy (aStr, "\pKenneth A. Long");    
  73.  
  74.     TextFace (condense);
  75.     MoveTo (((aboutW->portRect.right) - StringWidth ((StringPtr) aStr)) /2, 22);
  76.     DrawString ((StringPtr) aStr);
  77.  
  78.     TextSize (12);
  79.     
  80.     ForeColor (redColor);
  81.  
  82.     strcpy (aStr, "\pInventor - Industrial Artist - Writer");
  83.     TextFace (condense);
  84.     MoveTo (((aboutW->portRect.right) - StringWidth ((StringPtr) aStr)) /2, 40);
  85.     DrawString ((StringPtr) aStr);
  86.     TextFace (0);
  87.  
  88.     TextFont (3);
  89.     TextSize (9);
  90.  
  91.     ForeColor (blackColor);
  92.  
  93.     strcpy (aStr, "\pMacintosh Programmer (in training)");
  94.     MoveTo (((aboutW->portRect.right) - StringWidth ((StringPtr) aStr)) /2, 58);
  95.     DrawString ((StringPtr) aStr);
  96.  
  97.     strcpy (aStr, "\p");
  98.     MoveTo (((aboutW->portRect.right) - StringWidth ((StringPtr) aStr)) /2, 70);
  99.     DrawString ((StringPtr) aStr);
  100.  
  101.     ForeColor (redColor);
  102.  
  103.     strcpy (aStr, "\p\"Where there's a will, there's a way!\"");
  104.     MoveTo (((aboutW->portRect.right) -StringWidth ((StringPtr) aStr)) /2, 80);
  105.     DrawString ((StringPtr) aStr);
  106.  
  107.     ForeColor (blackColor);
  108.  
  109.     SetRect (&iconRect, 110, 90, 142, 122);
  110.  
  111.     if (gMac.systemVersion >= 0x0700) 
  112.     {
  113.         PlotIconID (&iconRect, 0, 0, 128);
  114.     } 
  115.     else 
  116.         {
  117.             ourIcon = GetResource ('ICN#', 128);
  118.             PlotIcon (&iconRect, ourIcon);
  119.     
  120.     }
  121.     
  122.     ReleaseResource (ourIcon);
  123.  
  124.     strcpy (aStr, "\pkenlong@netcom.com");
  125.     MoveTo (aboutW->portRect.left+4 , aboutW->portRect.bottom - 4);
  126.     DrawString ((StringPtr) aStr);
  127.  
  128.     strcpy (aStr, "\pkenlong@aol.com");
  129.     MoveTo (aboutW->portRect.right - 
  130.             StringWidth ((StringPtr) aStr) - 4 , 
  131.             aboutW->portRect.bottom - 4);
  132.             
  133.     DrawString ((StringPtr) aStr);
  134. }
  135.  
  136. void NewAbout (void) 
  137. {
  138.     GrafPtr        tempPort;
  139.  
  140.     //• Rather than using a dialog, just create a window to draw the
  141.     //• "About..." stuff in.
  142.     
  143.     GetPort (&tempPort);
  144.     InitCursor ();
  145.     SetRect (&aRect, 0, 0, 252, 144);
  146.     centerrect (&aRect, &qd.screenBits.bounds);
  147.     if (gMac.hasColorQD) 
  148.         aboutW = NewCWindow (nil, &aRect, "\pWindow", FALSE, 3, (WindowPtr) -1, FALSE, 0);
  149.     else
  150.         aboutW = NewWindow (nil, &aRect, "\pWindow", FALSE, 3, (WindowPtr) -1, FALSE, 0);
  151.     
  152.     SetPort (aboutW);
  153.     ForeColor (redColor);
  154.     zoomport (aboutW, TRUE);
  155.  
  156.     aboutDone = FALSE;
  157.     
  158.     //• do our own event-handling until the user either clicks the 
  159.     //• mouse, or presses a key on the keyboard
  160.  
  161.     do
  162.     {
  163.         if (GetNextEvent (everyEvent, &aboutEvt)) 
  164.         {
  165.             switch (aboutEvt.what) 
  166.             {
  167.                 case updateEvt:        
  168.                 {
  169.                     BeginUpdate (aboutW);
  170.                     drawabout ();
  171.                     EndUpdate (aboutW);
  172.                 }
  173.                 break;
  174.                                             
  175.                 case keyDown:
  176.                 case autoKey:
  177.                 case mouseDown:
  178.                     aboutDone = TRUE;
  179.                 break;
  180.                                             
  181.                 default:
  182.                 break;
  183.             }
  184.         }
  185.     }while (!aboutDone);
  186.     HideWindow (aboutW);
  187.     zoomport (aboutW, FALSE);
  188.     DisposeWindow (aboutW);
  189.     SetPort (tempPort);
  190. }
  191.  
  192. int Blend (int i1, int i2) 
  193. {
  194.     Fixed    smallFix, bigFix, tempFix;
  195.  
  196.     smallFix = ONE * i1;
  197.     bigFix = ONE * i2;
  198.     tempFix = FixMul (fract, bigFix) +FixMul (ONE-fract, smallFix);
  199.     return (FixRound (tempFix));
  200. }
  201.  
  202. void zoomrect (Rect *smallrect, Rect *bigrect, Boolean zoomup) 
  203. {
  204.     Fixed        factor;
  205.     Rect        rect1, rect2, rect3, rect4;
  206.     GrafPtr        savePort, deskPort;
  207.     int            i;
  208.     long        tm;
  209.  
  210.     GetPort (&savePort);
  211.     OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort)));
  212.     InitPort (deskPort);
  213.     SetPort (deskPort);
  214.     PenPat (&qd.gray);        //• Original, comment for black zoom.
  215. //    PenPat (&qd.black);        //• Uncomment for black zoom.
  216.     PenMode (notPatXor);    //• Original, comment for black zoom.
  217. //    PenMode (patXor);        //• Uncomment for black zoom.
  218.     if (zoomup) 
  219.     {
  220.         rect1 = *smallrect;
  221.         factor = FixRatio (6, 5);
  222.         fract = FixRatio (541, 10000);
  223.     }
  224.     else
  225.         {
  226.             rect1 = *bigrect;
  227.             factor = FixRatio (5, 6);
  228.             fract = ONE;
  229.     }
  230.     rect2 = rect1;
  231.     rect3 = rect1;
  232.     FrameRect (&rect1);
  233.     for (i = 1; i <= ZOOMSTEPS; i++) 
  234.     {
  235.         rect4.left = Blend (smallrect->left, bigrect->left);
  236.         rect4.right = Blend (smallrect->right, bigrect->right);
  237.         rect4.top = Blend (smallrect->top, bigrect->top);
  238.         rect4.bottom = Blend (smallrect->bottom, bigrect->bottom);
  239.         FrameRect (&rect4);
  240.         FrameRect (&rect1);
  241.         rect1 = rect2;
  242.         rect2 = rect3;
  243.         rect3 = rect4;
  244.         fract = FixMul (fract, factor);
  245.         tm = TickCount ();
  246.         while (tm == TickCount ());
  247.         tm = TickCount ();
  248.         while (tm == TickCount ());
  249.     }
  250.     FrameRect (&rect1);
  251.     FrameRect (&rect2);
  252.     FrameRect (&rect3);
  253.     ClosePort (deskPort);
  254.     DisposPtr ((Ptr) deskPort);
  255.     PenNormal ();
  256.     SetPort (savePort);
  257. }
  258.  
  259. void ltog (Rect *r) 
  260. {
  261.     Point    p1, p2;
  262.  
  263.     p1 = topLeft (*r);
  264.     p2 = botRight (*r);
  265.     LocalToGlobal (&p1);
  266.     LocalToGlobal (&p2);
  267.     Pt2Rect (p1, p2, r);
  268. }
  269.  
  270. void zoomport (WindowPtr wind, Boolean up) 
  271. {
  272.     Rect    r1, r2, r3;
  273.     
  274.     SetPort (wind);
  275.     SetRect (&r1, qd.screenBits.bounds.right / 2, 0,
  276.                   qd.screenBits.bounds.right / 2, 0);
  277.  
  278.     r3 = wind->portRect;
  279.     r2 = r3;
  280.     InsetRect (&r2, (r3.right - r3.left + 20) /2, 
  281.                   (r3.bottom - r3.top + 20) /2);
  282.     
  283.     ltog (&r2);
  284.     ltog (&r3);
  285.     
  286.     if (up) 
  287.     {
  288.         zoomrect (&r1, &r2, TRUE);
  289.         zoomrect (&r2, &r3, TRUE);
  290.         ShowWindow (wind);
  291.         SetPort (wind);
  292.     }
  293.     else
  294.         {
  295.             HideWindow (wind);
  296.             zoomrect (&r2, &r3, FALSE);
  297.             zoomrect (&r1, &r2, FALSE);
  298.     }
  299. }
  300.     
  301. void centerwindow (WindowPtr wind, Rect *r) 
  302. {
  303.     Rect    r2;
  304.     
  305.     r2 = wind->portRect;
  306.     MoveWindow     (wind, 
  307.                  ((r->right-r->left) - 
  308.                   (r2.right-r2.left)) /2 - r->left, 
  309.                  ((r->bottom-r->top) - 
  310.                   (r2.bottom-r2.top)) /2 - r->top, 
  311.                    false);
  312. }
  313.  
  314. void centerrect (Rect *r1, Rect *r2) 
  315. {
  316.     OffsetRect     (r1, 
  317.                  ((r2->right  - r2->left) -
  318.                  (r1->right  - r1->left)) / 2 - r1->left, 
  319.                  ((r2->bottom - r2->top)  -
  320.                  (r1->bottom - r1->top)) / 2 - r1->top);
  321. }
  322.  
  323.  
  324. void InitMacintosh (void) 
  325. {
  326.     MaxApplZone ();
  327.     
  328.     InitGraf (& (qd.thePort));
  329.     InitFonts ();
  330.     FlushEvents (everyEvent, 0);
  331.     InitWindows ();
  332.     InitMenus ();
  333.     TEInit ();
  334.     InitDialogs (0L);
  335.     InitCursor ();
  336.     SysEnvirons (1, &gMac);
  337. }
  338.  
  339. void main (void) 
  340. {
  341.     InitMacintosh ();
  342.     NewAbout ();
  343. }
  344.